<?php
declare (strict_types = 1);

namespace app\model;

use think\Model;
use think\model\concern\SoftDelete;
/**
 * @property \app\model\QuestionAnswer[] $answer 回复数量
 * @property bool $status 状态:0=下架,1=上架
 * @property int $browse 围观人数
 * @property int $class_id 类目
 * @property int $comment 互动人数
 * @property int $deletetime
 * @property int $id
 * @property int $reght_id 采纳id
 * @property int $score 积分
 * @property int $users_id 用户
 * @property string $adcode
 * @property string $content 内容
 * @property string $createtime
 * @property string $down_images 下架图片
 * @property string $down_reason 下架原因
 * @property string $images 图片
 * @property string $title 标题
 * @property-read \app\model\Users $users
 * @property-read \app\model\UsersCollect $users_collect
 * @property-read mixed $reght_status_text
 * @method static \think\db\Query onlyTrashed()
 * @method static \think\db\Query withTrashed()
 * @mixin \think\Model
 */
class Question extends Model
{
    use SoftDelete;
    protected $deleteTime = 'deletetime';
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    // 追加属性
    protected $append = [
        'reght_status_text'
    ];

    public function users()
    {
        return $this->belongsTo(Users::class, 'users_id');
    }

    public function answer()
    {
        return $this->hasMany(QuestionAnswer::class,'paper_id');
    }


    public function getReghtStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['reght_id']) ? $data['reght_id'] : '');
        return $value!=0 ? '已采纳' : '进行中';
    }
	
	public function usersCollect()
	{
		return $this->hasOne(UsersCollect::class,'pro_id');
	}
	
	
	
	
	
}
